export function groupArrayByRange (array, ranges, key) {
  const groups = {}

  // 初始化分组
  ranges.forEach(range => {
    groups[range.title] = {
      title: range.title,
      color: range.color,
      num: 0
    }
  })

  array.forEach(item => {
    const element = item[key]
    // 遍历范围对象
    ranges.forEach(range => {
      if ((range.min === null || element >= range.min) && (range.max === null || element <= range.max)) {
        groups[range.title].num++
      }
    })
  })
  return groups
}
